<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>用户组管理</title>
	<!--[if IE]>
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<![endif]-->
	<!-- Main Stylesheet --> 
	<link rel="stylesheet" href="<%=request.getContextPath()%>/css/style.css" type="text/css" />
	<!-- Your Custom Stylesheet --> 
	<link rel="stylesheet" href="<%=request.getContextPath()%>/css/custom.css" type="text/css" />
	<link href="<%=request.getContextPath()%>/lib/thickbox/thickbox.css" rel="stylesheet" type="text/css" />
	<link href="<%=request.getContextPath()%>/lib/jquery/jquery.autocomplete.css" type="text/css" rel="stylesheet"/>
	<%@include file="/include/header.jsp" %>
	<style type="text/css">
		#show_area input[type="text"]{
			font-family:宋体;黑体;幼圆;楷体_GB2312;仿宋_GB2312;Arial,Helvetica,sans-serif;
			border:0px;width:100%;height:100;
		}
		.noborder {border:0px none; overflow:auto;}
	</style>
	<script src="<%=request.getContextPath()%>/lib/jquery/jquery-1.4.2.min.js"></script>
	<script src="<%=request.getContextPath()%>/js/administry.js"></script>
	<script src="<%=request.getContextPath()%>/lib/validator/formValidator_min.js"></script>
	<script src="<%=request.getContextPath()%>/lib/validator/formValidatorRegex.js"></script>
	<script src="<%=request.getContextPath()%>/lib/jquery/jquery.form.js"></script>
	<script src="<%=request.getContextPath()%>/lib/datepicker/WdatePicker.js"></script>
	<script src="<%=request.getContextPath()%>/lib/thickbox/thickbox.js"></script>
	<script src="<%=request.getContextPath()%>/lib/jquery/jquery.autocomplete.pack.js"></script>
	<script src="<%=request.getContextPath()%>/js/function.js"></script>
	<script src="<%=request.getContextPath()%>/js/page/pageRender.js"></script>
	<script type="text/javascript">
	function showAddGroupForm(){
		getById("addGroup").reset();
		showBox("#TB_inline?height=280&width=500&inlineId=edit_container", "增加用户组");
	}
	window.onload = init;
	function init(){
		
		window["PAGEBAR"] = new PageRender({
			method: 'POST',
			url:'<%=request.getContextPath()%>/protected/system/listGroup.action',
			start: <s:property value="start"/>,
			limit: <s:property value="limit"/>,
			total: <s:property value="total"/>,
			data: {
				"groupName" : "#s_groupName",
				"orderby" : "#orderby",
				"markLocked" : "#markLocked",
				"mark" : "#mark"
			}
		});
		window["PAGEBAR"].render(getById("page_bar"));
	}
	function doSearch(){
		Mask.show();
		window["PAGEBAR"].position(1);
	}
	
	$(document).ready(function(){
		<sec:authorize ifAnyGranted="ADMIN,GROUP_ADD">
		$.formValidator.initConfig({
			formID:"addGroup",
			onError:function(msg){
				Alert(msg);
			},
			onSuccess:function(){
				if( confirm("准备提交数据，是否继续？") ){
					Mask.show();
					$('#addGroup').ajaxSubmit(function(rslt){Ajax.callback(rslt, function(){
						Mask.hide();
						tb_remove();
						doSearch();
					});});
				}
				return false;
			}
		});
		$("#code").formValidator({
			onShow:"请输入用户组编码",
			onFocus:"2-30个字符（数字、英文字母、下划线、横线）"
		}).inputValidator({min:2,max:30}).regexValidator({dataType:"enum", regExp:'username'});
		$("#name").formValidator({
			onShow:"请输入用户组名",
			onFocus:"2-30个字符",
		}).inputValidator({min:2,max:30});
		</sec:authorize>
		
		//AutoComplete用户组名关键字输入框
		$("#s_groupName").autocomplete(
		'<%=request.getContextPath()%>/protected/system/autoCompleteGroup.action',
		{
			width: 200,
			max: 10,
			scroll: true,
			scrollHeight: 300,
			dataType: 'json',
			matchCase:true,
			parse: function(data) {
				if(!isArray(data)){
					data = eval("("+data+")");
				}
				var rows = [];
				for(var i=0; i<data.length; i++){
					rows.push({
						"data" : data[i],
						"value" : data[i][1],
						"result" : this.formatResult && this.formatResult(data[i], data[i][1]) || data[i][1]
					});
				}
				return rows;
			},
			formatItem: function(data, i, total) {
				return data[0]+" | " + data[1];
			}
		});
		
		$("#mark").autocomplete(
		'<%=request.getContextPath()%>/protected/system/autoCompleteMarkGroup.action',
		{
			width: 160,
			max: 10,
			scroll: true,
			scrollHeight: 300,
			dataType: 'json',
			matchCase:true,
			parse: function(data) {
				if(!isArray(data)){
					data = eval("("+data+")");
				}
				var rows = [];
				for(var i=0; i<data.length; i++){
					rows.push({
						"data" : data[i],
						"value" : data[i],
						"result" : this.formatResult && this.formatResult(data[i], data[i]) || data[i]
					});
				}
				return rows;
			},
			formatItem: function(data, i, total) {
				return data;
			}
		});
	});
	</script>
</head>
<body>
	<%@include file="/include/body.jsp" %>
	
<s:if test="flag">
	<!-- 显示操作成功 -->
	<script type="text/javascript">
		showTip("操作成功");
	</script>
</s:if>

<s:if test="flag">
	<!-- 显示操作成功 -->
</s:if>
<%
	int p = (Integer) request.getAttribute("SEC_PRIORITY");
	int[] prioritys = new int[p];
	for(int i=p,j=0; i>0; i--,j++){
		prioritys[j] = i;
	}
	if(p>=40){
		pageContext.setAttribute("dp", p - 20);
	}else{
		pageContext.setAttribute("dp", p - 1);
	}
	pageContext.setAttribute("prioritys", prioritys);
%>
<!-- Wrapper -->
<div class="wrapper">
	
    <div class="content-box resizable" id="query_area">
    	<header>
			<h3>搜索</h3>
		</header>
		<section>
		<table class="no-style">
			<tbody>
			<tr>
				<td>
		        	<span>用户组名关键字:
		        		<input id="s_groupName" type="text" name="s_groupName" value="<s:property value="groupName"/>" class="input input_wa" />
		        	</span>
		        	<span>标识关键字:
		        		<input id="mark" type="text" name="mark" value="<s:property value="mark"/>" class="input input_wa" />
		        	</span>
			    	<span>锁定状态：
			    		<s:select id="markLocked" value="markLocked" theme="simple" list="#{'2':'全部','0':'未锁定','1':'锁定'}">
			    		</s:select>
			    	</span>
		            <span>
						<button class="btn" type="submit" onclick="doSearch();"><span class="icon icon-search"></span>搜 索</button>
					</span>
				</td>
			</tr>
			</tbody>
		</table>
		</section>
	</div>
    <div class="content-box" id="show_area">
	<header>
		<h3>
			<span>用户组列表</span>
	    	<span>排序：
	    		<s:bean name="java.util.ArrayList">
	    		</s:bean>
	    		<s:select id="orderby" value="orderby" onchange="doSearch();" theme="simple" 
	    			list="#{' order by code':'编码',' order by name':'用户组名',' order by priority asc':'等级:升序',' order by priority desc':'等级:降序'}">
	    		</s:select>
	    	</span>
	    </h3>
	    <div>
    	<sec:authorize ifAnyGranted="ADMIN,GROUP_ADD">
	    	<span>
	    		<span>
	    			<a class="btn btn-gray" href="javascript:void(0)" onclick="doSearch();"><span class="icon icon-refresh"></span>刷新</a>
	    		</span>
	    		<span>
	    			<a class="btn" href="javascript:void(0)" onclick="showAddGroupForm();"><span class="icon icon-add"></span>增加用户组..</a>
	    		</span>
	    	</span>
	    </sec:authorize>
	    </div>
	</header>
	<section>
     <table class="display stylized" id="data_table">
     	<thead>
		<tr>
			<th>序号</th><th>编码</th><th>用户组名</th>
			<th>标识</th><th>标识锁定</th><th>等级</th>
			<th>描述</th><th>操作</th>
		</tr>
		</thead>
		<tbody>
		<s:if test="groups != null">
			<s:iterator value="groups" status="groupstatus">
			<form id="form_<s:property value="code"/>" action="<s:url value='editGroup.action'></s:url>" method="post">
				<tr>
					<td><s:property value="#groupstatus.index + 1 + start"/></td>
					<td>
						<s:property value="code"/>
						<input type="hidden" name="group.code" value="<s:property value="code"/>"/>
					</td>
			 		<td><input type="text" name="group.name" value="<s:property value="name"/>"/></td>
			 		<s:if test="#attr.SEC_ISMARKLOCKED">
			 		<td>
			 			<s:property value="mark"/>
			 			<input type="hidden" name="group.mark" value="<s:property value="mark"/>" />
			 		</td>
		 			<td>
		 				<input type="hidden" name="group.markLocked" value="<s:property value="markLocked"/>" />
		 				<s:if test="markLocked">已锁定</s:if><s:else>未锁定</s:else>
		 			</td>
			 		</s:if>
			 		<s:else>
		 			<td><input type="text" name="group.mark" value="<s:property value="mark"/>"/></td>
		 			<td>
		 				<input type="checkbox" name="group.markLocked" value="true" <s:if test="markLocked">checked</s:if>/>
		 			</td>
			 		</s:else>
			 		<td>
			 			<select name="group.priority">
			 				<s:iterator value="#attr.prioritys" var="p">
								<option value="<s:property />" <s:if test="#p==priority">selected</s:if>><s:property /></option>
							</s:iterator>
			 			</select>
			 		</td>
			 		<td><input type="text" name="group.desn" value="<s:property value="desn"/>" /></td>
			 		<td>
			 		<sec:authorize ifAnyGranted="ADMIN,GROUP_UPDATE">
			 			<a href="javascript:void(0);" onclick="if(confirm('请确认')){Mask.show();$('#form_<s:property value="code"/>').ajaxSubmit(Ajax.callback);}">［更新］</a>
			 		</sec:authorize>
			 		<s:if test="'SYSTEM' != mark">
			 		<sec:authorize ifAnyGranted="ADMIN,GROUP_DELETE">
			 			<a href="javascript:void(0);" onclick="if(confirm('是否删除用户组?')){document.location.href='<s:url value='delGroup.action?id=%{code}'></s:url>';}">［删除］</a>
			 		</sec:authorize>
			 		</s:if>
			 		</td>
			 	</tr>
			 	</form>
			</s:iterator>
		 </s:if>
		 </tbody>
	</table>
	<div id="page_bar"></div>
	</section>
	</div>
</div>

<div id="edit_container" style="display:none;">
 <div id="edit_area">
  <sec:authorize ifAnyGranted="ADMIN,GROUP_ADD">
	<s:form id="addGroup" action="addGroup.action" method="post" theme="simple">
	<table class="no-style">
		<tr>
			<td><label class="required">编码</label></td>
			<td><input id="code" type="text" name="group.code" value=""/></td>
			<td><div id="codeTip"></div></td>
		</tr>
		<tr>
			<td><label class="required">用户组名</label></td>
			<td><input id="name" type="text" name="group.name" value=""/></td>
			<td><div id="nameTip"></div></td>
		</tr>
		<tr>
			<td><label>等 级</label></td>
			<td>
				<select name="group.priority">
					<s:iterator value="#attr.prioritys" var="v">
						<option value="<s:property />" <s:if test="#attr.dp==#v">selected</s:if>><s:property /></option>
					</s:iterator>
				</select>
			</td>
			<td></td>
		</tr>
		<s:if test="! #attr.SEC_ISMARKLOCKED">
		<tr>
			<td><label>标识码</label></td>
			<td><input type="text" name="group.mark" value=""/></td>
			<td></td>
		</tr>
		<tr>
			<td><label>标识码锁定</label></td>
			<td><input type="checkbox" name="group.markLocked" value="true" checked/></td>
			<td></td>
		</tr>
		</s:if>
		<tr>
			<td><label>描述</label></td>
			<td><input id="desn" type="text" name="group.desn" value=""/></td>
			<td><div id="desnTip"></div></td>
		</tr>
	</table>
	<div class="form-btn">
		<button class="btn btn-green" type="submit"><span class="icon icon-ok"></span>提 交</button>
		<button class="btn" type="reset" onclick="javascript:tb_remove();"><span class="icon icon-close"></span>取消</button>
	</div>
	</s:form>
</sec:authorize>
</div>
</div>
	
</body>
</html>